package cn.hy.batch.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobInstanceAlreadyExistsException;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class StartJobByJobOperatorController {

   @Resource
    private JobOperator jobOperator;


    @RequestMapping("/jobStartByOperator/{name}")
    public String jobStart(@PathVariable String name) throws JobParametersInvalidException, JobInstanceAlreadyExistsException, NoSuchJobException {
        log.info("通过operator启动job");
        jobOperator.start("jobDemo2", "name=" + name);
        return "job start by operator";
    }

}
